<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        body {
            background-image: url(images/1.jpg);
        }
        
        .all {
            height: 65px;
            width: 420px;
            margin: 10px auto;
            background-color: #fff;
            padding-left: 5px;
        }
        
        .all img {
            margin-top: 2.5px;
            height: 60px;
            width: 100px;
            cursor: pointer;
        }
    </style>
</head>

<body>
    <!-- 先做出可供选择的图片 -->
    <div class="all">
        <img src="images/1.jpg" alt="">
        <img src="images/2.jpg" alt="">
        <img src="images/3.jpg" alt="">
        <img src="images/4.jpg" alt="">
    </div>
    <!-- 获取元素 -->
    <script>
        var bg = document.body;
        var choose = document.getElementsByTagName('img');
        console.log(choose);
        // 循环注册事件
        for (i = 0; i < choose.length; i++) {
            choose[i].onclick = function() {
                bg.style.backgroundImage = 'url(' + this.src + ')';
            }
        }
    </script>
</body>

</html>